/**
 * 维修收入结算-报工单开窗
 * @author miaoyl
 * @date 2019/04/08
 */
define(function () {

    var self,
        app = win.app,
        vueData = {
            tableData: [],
            count: 0,
            limit: 10,
            keyword: '',
            page: 1,
            operation: ''
        },
        table_where = {
            STR : [],
            MMRX032 : '',
            MMRX018 : ''
        },
        page = 1,
        cb
    ;

    app.newModule({
        init: function () {
            self = this;
            self._super({
                _tag: 'common_open_multi_mmrghi'
            }, win);
        },
        queryDatas: function () {
            app.ajax({
                xurl: 'crm/gwei025/getMmrhgiData',
                xdata: {
                    page: page,
                    limit: vueData.limit,
                    keyword: vueData.keyword,
                    STR: table_where.STR,
                    MMRX032: table_where.MMRX032,
                    MMRX018: table_where.MMRX018
                },
                cb: function (result) {
                    if (result.ok) {
                        vueData.tableData.pushArray(result.data.data,true);
                        vueData.count = result.data.count;
                    }
                }
            });
        },

        _call:function (obj) {
            vueData.keyword = '';
            page = 1;
            cb = obj.cb;
            table_where.STR = obj.STR;
            table_where.MMRX032 = obj.MMRX032;
            table_where.MMRX018 = obj.MMRX018;
            vueData.operation = obj.operation;
            self.queryDatas();
        },

        _ready: function () {
            new Vue({
                el: '#common_open_multi_mmrghi',
                data: vueData,
                methods: {
                    formatMC:function (row, column) {
                        if(row.GWAML003 != undefined){
                            return row.GWAML003;
                         }else if(row.MMRCL003 != undefined){
                            return row.MMRCL003;
                        }else {
                            return '';
                        }
                    },
                    getRowKeys: function (row) {
                        return row.ROW_ID;
                    },
                    selectRow: function (inx, row) {
                        app.log(inx, row);
                        cb(row);
                        page = 1;
                        vueData.page = 1;
                        layer.close(layer.index);
                    },
                    handleSizeChange: function (val) {
                        //console.log(`每页 ${val} 条`);
                    },
                    handleCurrentChange: function (val) {
                        page = val;
                        self.queryDatas();
                    },
                    queryDatas: function () {
                        page = 1;
                        vueData.page = 1;
                        self.queryDatas();
                    },
                    cancle: function (rows) {
                        page = 1;
                        vueData.page = 1;
                        layer.close(layer.index);
                        this.$refs.multipleTable.clearSelection();
                    },
                    handleSelectionChange: function (val) {
                        this.multipleSelection = val;
                        //layer.close(layer.index);
                    },
                    save: function () {
                        cb(this.multipleSelection);
                        this.multipleSelection = [];
                        page = 1;
                        vueData.page = 1;
                        layer.close(layer.index);
                        this.$refs.multipleTable.clearSelection();
                    },
                    transfer:function () {
                        cb(this.multipleSelection);
                        this.multipleSelection = [];
                        page = 1;
                        vueData.page = 1;
                        layer.close(layer.index);
                        this.$refs.multipleTable.clearSelection();
                    }
                },
                created: function () {
                    self._setEleIsReady('common_open_multi_mmrghi');
                }
            });
        },
        _lazy: function () {
            this._super();
        }
    });

});
